package com.xpec.c4.db.dao;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.xpec.c4.db.basic.BasicGameDAO;
import com.xpec.c4.db.hibernate.manager.HibernateManager;
import com.xpec.c4.db.model.CooperatorAccountModel;

/**
 * 模擬運營商帳號登入Table , 正式上線後不該有值
 * @author wuweijun
 *
 */
public class CooperatorAccountDAO extends BasicGameDAO {
	/**
	 * 新增账户数据
	 * 
	 * @param player
	 * @return
	 */
	public static boolean addAccountInfo(String accountId, String password) {
		CooperatorAccountModel model = new CooperatorAccountModel(accountId, password);
		HibernateManager.txBegin();
		save(model);
		return HibernateManager.txCommitFailRollbackClearSession();
	}
	public static CooperatorAccountModel loadAccountByAccountId(String accountId) {
		if (accountId == null) {
			return null;
		}
		Session session = HibernateManager.getSession();
		Criteria criteria = session.createCriteria(CooperatorAccountModel.class);
		criteria.add(Restrictions.eq("accountId", accountId));
		CooperatorAccountModel model = (CooperatorAccountModel) criteria.uniqueResult();
		HibernateManager.endSession();
		return model;
	}
}
